<%@page import="com.stu.utils.PageBean"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>

<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
<title>极客之家-新闻管理</title>

<meta name="keywords" content="keyword1,keyword2,keyword3">
<meta name="description" content="this is my page">
<meta name="content-type" content="text/html; charset=UTF-8">

<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->

<!-- 分页 -->
<link rel="stylesheet" href="<%=path%>/css/bootstrap-combined.css">
<link rel="stylesheet" href="<%=path%>/css/info_list.css">

<!-- 弹出框 -->
<link rel="stylesheet" type="text/css" href="<%=path%>/css/xcConfirm.css"/>

<style type="text/css">
	.tdC{
		text-align: center
	}
	.main{
    position:absolute;
    top:50%;
    left:50%;
    width:280px;
    height:80px;
    margin-top:-40px;
    margin-left:-140px;
    border:1px solid #ddd;
    background-color: #ddd;
    }
    body { font-family: "HelveticaNeue","Helvetica-Neue", "Helvetica", "Arial", sans-serif; }
			.big-link { display:block; margin-top: 100px; text-align: center; font-size: 70px; color: #06f; }
			
</style>

</head>

<body>
	<!-- top start -->
	<jsp:include page="top.jsp"></jsp:include>
	<!-- top end -->

	<div class="container-fluid divBlock">



		<%--加载中 start --%> 
		<div id="loading" >Loading...</div>  
		<%--加载中 end --%>
		
		<div class="row cotainer  infoTable">
			<table class="table table-hover">
				<caption class="text-center">
					<header class="toCenter">
						<h1> 
							<small> 缓存管理 </small>
						</h1>
						<hr style="width: 100%;">
					</header>
				</caption>
				<thead>
					<tr>
						<td class="  " style="text-align: center;">名称</td>
						<td class="  " style="text-align: center;">键</td>
						<td class="  " style="text-align: center;">操作</td>
					</tr>
				</thead>
				<tbody id="admin_news_list_tbody" style="text-align: center;">
					<tr>
						<td style="text-align: center;">新闻缓存</td>
						<td style="text-align: center;">news</td>
						<td style="text-align: center;"><a href="#" class="btn btn-default" id="clearNews">清空</a></td>
					</tr>
					<tr class="info">
						<td style="text-align: center;">博客缓存</td>
						<td style="text-align: center;">blogs</td> 
						<td style="text-align: center;"><a href="#" class="btn btn-default" id="clearBlogs">清空</a></td>
					</tr>
					<tr>
						<td style="text-align: center;">城市配置</td>
						<td style="text-align: center;">cityid</td>
						<td style="text-align: center;"><a href="javascript:showSelectCity()" class="btn btn-success"  data-reveal-id="selectCityModel" data-animation="fade">配置</a></td>
					</tr>
					<!-- <tr>
						<td style="text-align: center;">首页介绍配置</td>
						<td style="text-align: center;">introduce:text</td>
						<td style="text-align: center;"><a href="javascript:showSelectCity()" class="btn btn-success"  data-reveal-id="selectCityModel" data-animation="fade">配置</a></td>
					</tr> -->
					
				</tbody>


			</table>
		</div>
	</div>

	
	<div class="main" id="selectCityModel">
		<h3 style="align:center;margin:0 auto;">修改城市</h3>
		<select id="selectCity">
		</select>
	</div>


	<!-- 弹出框 -->
	<script type="text/javascript" src="<%=path%>/js/xcConfirm.js"></script>
	
	<script type="text/javascript">  
		$(function() {
			$("#loading").hide();
			$(".main").hide();
			var path='<%=path%>';
			
			
			
			/*清空新闻 */
			$("#clearNews").bind("click",function(){
				$.ajax({
					type : "GET",
					url : path + "/user_delRedisKey.action",
					data : {
						rediskey : "news",
					},
					dataType : "json",
					success : function(result) {
							alertSuccess("删除数据成功");
					},
					error:function(){
						alertError("网络连接失败~~");
					}
				});
			});
			/*情空博客*/
			$("#clearBlogs").bind("click",function(){
				$.ajax({
					type : "GET", 
					url : path + "/user_delRedisKey.action",
					data : {
						rediskey : "blogs",
					},
					dataType : "json",
					success : function(result) {
						alert(result.rediskey);
							alertSuccess("删除数据成功");
					},
					error:function(){
						alertError("网络连接失败~~");
					}
				});
			});
			
			/* 点击新闻删除  */
			$("#admin_news_list_delAll_btn").click(function() {
				var ids = getChecked();
				if (ids.length > 0) {
					$.ajax({
						type : "POST",
						url : path + "/newsAction_deleteNewsByIds.action",
						data : {
							ids : ids,
						},
						dataType : "json",
						success : function(result) {
							if (result.success) {
								alertSuccess("删除数据成功");
								refreshAdminNewsTable(path, 1);
							} else {
								alertError("删除数据失败");
							}
						},
						error:function(){
							alertError("网络连接失败~~");
						}
					}); 
				} else {
					alertError("请选中删除项");
				}
			});

			/* 点击查询  */
			$("#admin_search_btn").click(function() {
				refreshAdminNewsTable(path, 1);
				return false;/* 防止刷新整个页面  */
			})

			/* 全选/取消选中  */
			$("#checkAllAdminNews").bind("click", function() {
				if (this.checked) {
					$("input[type=checkbox]").prop("checked", 'true');
				} else {
					$("input[type=checkbox]").removeAttr("checked");
				}
			});

			
			/* 重新抓取新闻  */
			$("#admin_news_get").click(function() {
				
				$("#loading").show();
				$("#loading").addClass("loading");
				
				$.ajax({
					type : "POST",
					url : path + "/newsAction_saveNews.action",
					data : {
						title : $("#a_s_title").val(),
					},
					dataType : "json",
					success : function(result) {
						if (result.success) {
							alertSuccess("抓取数据成功");
							refreshAdminNewsTable(path, 1);
							$("#loading").hide();
							$("#loading").removeClass("loading");
						} else {
							alertError("抓取数据失败");
							$("#loading").hide();
							$("#loading").removeClass("loading");
						}
					}
				});
			});
			
		});

		
		function showSelectCity(){
			
			$.ajax({
				type : "POST",
				url : path + "/user_getZRevRange.action",
				data : {
					rediskey : "citys"
				},
				dataType : "json",
				success : function(result) {
					var d=result.redisvalue;
					var o="";
					for(var i=0;i<d.length;i++){
						o+="<option value="+d[i].value+">"+d[i].key+"</option>";
					}
					var txt='<select id="redisvalue" name="redisvalue">'+o+'</select>';

					var option = {
							title: "修改城市",
							btn: parseInt("0011",2),
							onOk: function(){
						var value=$("#redisvalue").val();
								$.ajax({
									type : "POST",
									url : path + "/user_setToRedis.action",
									data : {
										"rediskey":"cityid",
										"redisvalue":value
									},
									dataType : "json",
									success : function(result) {
										alertSuccess("修改城市成功");
										window.location.reload();
									}
								});
							}
						};
						window.wxc.xcConfirm(txt, "custom", option);
						
				}
			}); 
			
			
		}
	</script>
	<!--  js end -->

</body>
</html>